package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.views.PermissionView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface PermissionViewMapper extends JpaRepository<PermissionView, Long>, JpaSpecificationExecutor<PermissionView> {

    @Query(value = "select p from PermissionView p where p.applicationId = :appId and p.permissionCode = :permissionCode")
    PermissionView findByPermissionCode(long appId, String permissionCode);

    @Query(value = "select p from PermissionView p where p.applicationId = :appId and p.permissionName = :permissionName")
    Collection<PermissionView> findListByPermissionName(long appId, String permissionName);

    @Query(value = "select p from PermissionView p where p.applicationId = :appId and p.permissionGroup = :permissionGroup")
    Collection<PermissionView> findListByPermissionGroup(long appId, String permissionGroup);

    Page<PermissionView> findAll(Specification<PermissionView> specification, Pageable pageable);
}
